package exam.axhu.junit;

import static org.junit.Assert.*;

import java.util.List;

import exam.axhu.entity.Teacher;
import exam.axhu.service.TeacherService;

import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TeacherTest {
	private static TeacherService teacherService;
	
	@BeforeClass
	public static void setUpBeforeClass() throws Exception{
		try {
			ApplicationContext act = new ClassPathXmlApplicationContext("beans.xml");
			teacherService =(TeacherService) act.getBean("teacherServiceImpl");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	@Test
	public void save() {
		if(teacherService.save(new Teacher("T12345","赵ha","123456"))==1)
			System.out.println("already have!");
	
	}
	
	@Test
	public void update() {
		Teacher em = teacherService.find("T1000568");
		em.setName("刘武");
		teacherService.update(em);
	}
	
	@Test
	public void delete() {
		teacherService.delete("T1000568");
	}
	
	@Test
	public void list() {
		List<Teacher> ems = teacherService.list();
		for(Teacher em : ems)
			System.out.println(em.getName());
	}
	
	@Test
	public void find() {
		Teacher em = teacherService.find("T1000508");
		if (em!=null)
			System.out.println(em.getPassword());
		else System.out.println("not found");
	}
	


}
